var _isIE6 = ($.browser.msie && $.browser.version == '6.0');
var _isIPAD = navigator.userAgent.match(/iPad/i);

var _ebizLoading = $("#ebiz-loading");
var _ebizLoadingOverlay = $("#ebiz-loading-overlay");
function loading() {
	if (_ebizLoading.length == 0) {
		$('body')
				.append(
						_ebizLoading = $('<div id="ebiz-loading"><div id="ebiz-loading-img"></div></div>'),
						_ebizLoadingOverlay = $('<div id="ebiz-loading-overlay"></div>'));
		$("#ebiz-loading-img")
				.css(
						{
							"width" : "24px",
							"height" : "24px",
							"padding" : "10px",
							"background" : "url('"
									+ _RESOURCE_PATH
									+ "/images/fancybox_loading.gif') center center no-repeat"
						});
		_ebizLoading.css({
			"position" : (_isIE6 || _isIPAD) ? "absolute" : "fixed",
			"top" : "50%",
			"left" : "50%",
			"width" : "44px",
			"height" : "44px",
			"margin-top" : "-22px",
			"margin-left" : "-22px",
			"background-position" : "0 -108px",
			"opacity" : "0.8",
			"background-image" : "url('" + _RESOURCE_PATH
					+ "/images/fancybox_sprite.png')",
			"display" : "none",
			'z-index' : 9999
		});
		_ebizLoadingOverlay.css({
			'position' : 'absolute',
			'top' : 0,
			'left' : 0,
			'background-color' : '#ccc',
			'opacity' : 0.6,
			'display' : 'none',
			'z-index' : 9998
		});

		// bycobe 20120813: fix IE6 for mask select box !
		if (_isIE6) {
			$(
					"<iframe id='ebiz-loading-iframe' src='" + _RESOURCE_PATH
							+ '/html/blank.htm' + "'></iframe>").appendTo(
					_ebizLoadingOverlay).css({
				'background-color' : '#ccc',
				'z-index' : 9997,
				'filter' : "alpha(opacity=0)"
			});
		}
	}
	// bycobe 20120813: fix IE6 for mask select box !
	if (_isIE6) {
		$("#ebiz-loading-iframe").css({
			'width' : '100%',
			'height' : $(document).height()
		});
	}
	_ebizLoadingOverlay.css({
		'width' : '100%',
		'height' : $(document).height()
	}).show();
	_ebizLoading.show();
}

function loginChecking() {
	//if (!checkInput("ada", "[0-9]{4,11}")
	if(!checkInput("ada", "\\w{4,}")
			//|| !checkInput("password", "[0-9]{6,15}")
			|| checkPwd("password")
			|| (_needCheckCode && !checkInput("checkCode", "[0-9]{4,4}"))) {
		return false;
	}
	return true;
}
//判断pwd的长度
function checkPwd(id){
	var $o = $("#" + id);
	if ($o.length == 0 || $o.val().length<6) {
		alert($o.attr("msg"));
		return true;
	}
}

function checkInput(id, reg) {
	var $o = $("#" + id);
	if ($o.length == 0) {
		return true;
	}

	$o.val($.trim($o.val()));

	if (!$o.val().match(new RegExp(reg))) {
		//$o.addClass("error").focus();
		alert($o.attr("msg"));
		return false;
	} else {
		$o.removeClass("error");
	}
	return true;
}

function myLoginSubmit() {
	if (loginChecking()) {
		loading();
		authorize_form.submit();		
	}
}

function refreshCheckCode() {
	$("#imgCheckCode").attr("src",
			_RESOURCE_PATH + "/checkCode?ts=" + new Date().getTime());
}

function closeWebPage() {
	if (window.confirm("确认取消登录并关闭本页面吗？")) {
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
				window.opener = null;
				window.close();
			} else {
				window.open('', '_top');
				window.top.close();
			}
		} else if (navigator.userAgent.indexOf("Firefox") > 0) {
			window.location.href = 'about:blank ';
			// window.history.go(-2);
		} else {
			window.opener = null;
			window.open('', '_self', '');
			window.close();
		}
	}
}